package com.android.boncen.commonFrame.fragment.recommend_framents;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.android.boncen.commonFrame.R;
import com.android.boncen.commonFrame.activity.Webview_detail_activity;
import com.android.boncen.commonFrame.adapter.MyRecyclerViewAdapter;

/**
 * Created by Boncen on 2017/1/24.
 */

public class recommend_sport_fragment extends Fragment {
    private String title;
    private View rootView;
    private Context mContext;

    private RecyclerView recycleView;
//    private ListView listView_sportProject;

    private String[] sports_name = {"快走","慢跑","骑行","爬山","水中健身","游泳","踢毽子","羽毛球","广场舞"};
    private int[] sports_imgs = {R.drawable.walk,R.drawable.jogging,R.drawable.bike,R.drawable.climbmountain,
            R.drawable.sport_in_water,R.drawable.swimming,R.drawable.tijianzi,
            R.drawable.badminton,R.drawable.dance};
    private String baseUrl = "http://baike.baidu.com/item/";

    public recommend_sport_fragment(){}
    public recommend_sport_fragment(Context context,String title){
        this.mContext = context;
        this.title = title;
    }

    public String getTitle() {
        return title;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if (rootView==null){
            rootView = View.inflate(mContext, R.layout.sport_view,null);
        }
        recycleView = (RecyclerView) rootView.findViewById(R.id.sport_recycleview);
        LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
        layoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
        recycleView.setLayoutManager(layoutManager);
        MyRecyclerViewAdapter adapter = new MyRecyclerViewAdapter(mContext,sports_name,sports_imgs);
        adapter.setOnItemClickListener(new MyRecyclerViewAdapter.OnItemClickListener() {
            @Override
            public void OnItemClick(View view, int position) {
                Intent intent = new Intent(mContext, Webview_detail_activity.class);
                intent.putExtra("title",sports_name[position]);
                intent.putExtra("url",baseUrl+sports_name[position]);
                mContext.startActivity(intent);
            }
        });
        recycleView.setAdapter(adapter);
        return  rootView;
    }

}
